package designMode.statePattern.after;

/**
 * @author LIBOFEI
 * @ClassName WinnerState
 * @description
 * @date 2020/6/28 16:52
 * @Version 1.0
 **/
public class WinnerState implements State {

    GumballMachine gumballMachine;

    public WinnerState(GumballMachine gumballMachine){
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("出错了");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("出错了");
    }

    @Override
    public void turnCrank() {
        System.out.println("出错了");
    }

    @Override
    public void dispense() {
        System.out.println("恭喜你中了两个糖果");
        gumballMachine.repleaseBall();
        if(gumballMachine.getCount() == 0){
            gumballMachine.setState(gumballMachine.getSoldOutState());
        }else{
            gumballMachine.repleaseBall();
            if(gumballMachine.getCount() > 0){
                gumballMachine.setState(gumballMachine.getNoQuarterState());
            }else{
                System.out.println("糖果已售完");
                gumballMachine.setState(gumballMachine.getSoldOutState());
            }
        }
    }
}
